Crate as_any[][src]

Expand description

This library provides some utility traits to make working with Any smoother. This crate contains similiar functionality to the downcast crate, but simpler.

Usage example

use as_any::{AsAny, Downcast};

struct Test;

trait Custom: AsAny {
    // whatever you like to put inside of your trait
}

// implements the downcasting methods
impl as_any::Downcast for dyn Custom {}
impl as_any::Downcast for dyn Custom + Send {}
impl as_any::Downcast for dyn Custom + Sync {}
impl as_any::Downcast for dyn Custom + Send + Sync {}

impl Custom for Test {}

fn lol() {
    let x = Test;
    let y: &dyn Custom = &x;
    y.downcast_ref::<Test>().unwrap();
}

Traits

This trait is an extension trait to Any, and adds methods to retrieve a &dyn Any

A trait for the conversion of an object into a boxed trait object.

This trait is an extension trait to AsAny, and adds methods for unchecked downcasts